package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    Integer exist(ShoppingCart shoppingCart);

    @Update("update shopping_cart set number = number + 1 where id = #{id}")
    void addNums(Integer shoppingCart);

    @Insert("insert into shopping_cart (name, image, dish_id, setmeal_id, dish_flavor, number, amount, create_time, user_id) values (#{name}, #{image}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime}, #{userId})")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    @Update("")
    void subShoppingCart(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where (dish_id = #{dishId} or setmeal_id = #{setmealId}) and dish_flavor = #{dishFlavor}  and user_id = #{userId}")
    ShoppingCart select(ShoppingCart shoppingCart);

    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    @Update("update shopping_cart set number = number - 1 where id = #{id}")
    void subNums(Long id);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);
}
